package com.ruoyi.web.controller.dingdan;

import java.util.List;

import com.ruoyi.system.service.IDingdanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dingdan;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 订单 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/dingdan")
public class DingdanController extends BaseController
{
    private String prefix = "system/dingdan";
	
	@Autowired
	private IDingdanService dingdanService;
	
	@RequiresPermissions("system:dingdan:view")
	@GetMapping()
	public String dingdan()
	{
	    return prefix + "/dingdan";
	}
	
	/**
	 * 查询订单列表
	 */
	@RequiresPermissions("system:dingdan:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Dingdan dingdan)
	{
		startPage();
        List<Dingdan> list = dingdanService.selectDingdanList(dingdan);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出订单列表
	 */
	@RequiresPermissions("system:dingdan:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dingdan dingdan)
    {
    	List<Dingdan> list = dingdanService.selectDingdanList(dingdan);
        ExcelUtil<Dingdan> util = new ExcelUtil<Dingdan>(Dingdan.class);
        return util.exportExcel(list, "dingdan");
    }
	
	/**
	 * 新增订单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单
	 */
	@RequiresPermissions("system:dingdan:add")
	@Log(title = "订单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Dingdan dingdan)
	{		
		return toAjax(dingdanService.insertDingdan(dingdan));
	}

	/**
	 * 修改订单
	 */
	@GetMapping("/edit/{dingdanId}")
	public String edit(@PathVariable("dingdanId") Integer dingdanId, ModelMap mmap)
	{
		Dingdan dingdan = dingdanService.selectDingdanById(dingdanId);
		mmap.put("dingdan", dingdan);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单
	 */
	@RequiresPermissions("system:dingdan:edit")
	@Log(title = "订单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Dingdan dingdan)
	{		
		return toAjax(dingdanService.updateDingdan(dingdan));
	}
	
	/**
	 * 删除订单
	 */
	@RequiresPermissions("system:dingdan:remove")
	@Log(title = "订单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dingdanService.deleteDingdanByIds(ids));
	}
	
}
